package com.cy.store.controller;

import com.cy.store.entity.Product;
import com.cy.store.service.IProductService;
import com.cy.store.util.JsonResult;
import com.cy.store.vo.ProductCategoryVO;
import com.cy.store.vo.ProductSearchVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("products")
public class ProductController extends BaseController {
    @Autowired
    private IProductService productService;

    @RequestMapping("hot_list")
    public JsonResult<List<Product>> getHotList() {
        List<Product> data = productService.findHotList();
        return new JsonResult<List<Product>>(OK, data);
    }

    @RequestMapping("new_product")
    public JsonResult<List<Product>> getNewProduct() {
        List<Product> data = productService.getNewProduct();
        return new JsonResult<List<Product>>(OK, data);
    }

    @RequestMapping("product_search")
    public JsonResult<ProductSearchVO> productSearch(
             String searchKeyword
            ,Integer pageNumber) {
        ProductSearchVO productSearchVO = productService.productSearch(searchKeyword, pageNumber);
        return new JsonResult<ProductSearchVO>(OK, productSearchVO);
    }

    @RequestMapping("productSearchType")
    public JsonResult<ProductSearchVO> productSearchType(
            Integer searchType
            ,Integer pageNumber) {
        ProductSearchVO productSearchVO = productService.productSearchType(searchType, pageNumber);
        return new JsonResult<ProductSearchVO>(OK, productSearchVO);
    }

    @RequestMapping("productCategory")
    public JsonResult<List<ProductCategoryVO>> productCategory() {
        List<ProductCategoryVO> productCategoryVOS = productService.productCategory();
        return new JsonResult<List<ProductCategoryVO>>(OK, productCategoryVOS);
    }





    @RequestMapping("{id}/details")
    public JsonResult<Product> getById(@PathVariable("id") Integer id) {
        Product data = productService.findById(id);
        return new JsonResult<Product>(OK, data);
    }
}
